package cn.lyjuan.payment.third.base.pay.chl.impl.weixin.enums;

import cn.lyjuan.base.util.StringUtils;

/**
 * 微信交易方式
 */
public enum WxTradeType
{
    /**
     * 微信公众号支付
     */
    JSAPI("JSAPI")
    /**
     * 扫码支付
     */
    , WEB_QRCODE("NATIVE")
    /**
     * APP
     */
    , APP("APP")
    /**
     * 手机H5调用微信APP支付
     */
    , WAP("MWEB");

    private String value;

    public String getValue()
    {
        return value;
    }

    WxTradeType(String value)
    {
        this.value = value;
    }

    /**
     * 将字符串解析为交易类型枚举类型
     * @param tradeType
     * @return
     */
    public static WxTradeType parse(String tradeType)
    {
        if (StringUtils.isNull(tradeType))
            throw new RuntimeException("ali service can not be null");

        if (tradeType.equalsIgnoreCase(JSAPI.value))
            return JSAPI;

        if (tradeType.equalsIgnoreCase(WEB_QRCODE.value))
            return WEB_QRCODE;

        if (tradeType.equalsIgnoreCase(APP.value))
            return APP;

        if (tradeType.equalsIgnoreCase(WAP.value))
            return WAP;

        throw new RuntimeException("wx trade type unsupported: " + tradeType);
    }
}
